package com.novelastudios.utils
{
	import flash.display.DisplayObject;

	public class LayoutXMLUtil
	{
		/**
		 * Really needs to be revisted! As right now, the capabilities are very limited.
		 *  
		 * @param value
		 * @param target
		 * @return 
		 * 
		 */		
		public static function getCalculated(value:String,target:DisplayObject):Number
		{
			var reg:RegExp = new RegExp("\\{[a-zA-Z0-9]\\}","g");
			
			var regResults:Array;
			var replaceReg:RegExp;
			var i:String;
			var ii:String;
			if(Boolean(value.match(reg)))
			{
				regResults = StringUtil.getBetween(value,"{","}");
				for (i in regResults ) 
				{
					try
					{
						replaceReg 	= new RegExp("\\{"+regResults[i]+"\\}","g");
						value 		= value.replace(replaceReg,target[regResults[i]]);
					}
					catch(error:Error)
					{
						throw new Error("Attribute value is not formatted correctly. Details: /n "+error.message);
					}
				}
				return MathUtil.calculateString(value);
			}
			else
			{
				return MathUtil.calculateString(value);
			}
		}
	}
}